'use strict'
const path = require('path')
// const defaultSettings = require('./src/settings.js')

const prod = 'http://groupbuy.xiongmaodangao.com/'
const dev = 'http://dev.groupbuy.xiongmaodangao.com/'

function resolve(dir) {
  return path.join(__dirname, dir)
}

// const Timestamp = new Date().getTime();

const name = '熊猫不走配送范围查询' // page title

// If your port is set to 80,
// use administrator privileges to execute the command line.
// For example, Mac: sudo npm run
// You can change the port by the following methods:
// port = 9528 npm run dev OR npm run dev --port = 9528
const port = process.env.port || process.env.npm_config_port || 8088 // dev port

// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {
  /**
   * You will need to set publicPath if you plan to deploy your site under a sub path,
   * for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,
   * then publicPath should be set to "/bar/".
   * In most cases please use '/' !!!
   * Detail: https://cli.vuejs.org/config/#publicpath
   */
  publicPath: './',
  outputDir: 'dist',
  assetsDir: 'static',
  // indexPath: "index-v2.0.0.25.html",
  lintOnSave: process.env.NODE_ENV === 'production',
  productionSourceMap: process.env.NODE_ENV === 'development',
  // filenameHashing: true,
  devServer: {
    port: port,
    open: false,
    overlay: {
      warnings: false,
      errors: true
    },
    // before: require('./mock/mock-server.js')
    proxy: {
      //如果代理不生效 请将将根目录的 .env.development 文件里的VUE_APP_BASE_API 改成自己的ip
      "/api": {
        changOrigin: true,
        target: prod,
        // target: "http://192.168.31.24:8101",
        pathRewrite: {"^/api" : "/api"} //正式服接口带api，本地Ip测试去掉api
      },
    }
  },
  chainWebpack: config => {
    config.when(process.env.NODE_ENV === 'development', // 开发环境
      // config => config.devtool('cheap-source-map') // 转换过的源码-快
      config => config.devtool('source-map') // 源码-慢
    )
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    // js打包编译后的文件名称【模块名称.时间戳】
    // output: {
    //   filename: `[name].${Timestamp}.js`,
    //   chunkFilename: `[name]${Timestamp}.js`
    // },
    name: name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
}
